package com.ra.landlord;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * 时间段（每月）的缴费记录 （实缴）， 总表(费用改造)
 * 
 * @author Shen.Kang Date: 2015-06-30
 */
@Entity
@Table(name = "ra_fee_record")
public class FeeRecord implements LandlordOwner {
	
	//费用状态:“已删除”
	public static final int FEE_STATUS_RENT_DELETE = 0;
	
	//费用状态:“已缴费”
	public static final int FEE_STATUS_RENT_DONE = 1;
	
	//费用状态:“未缴费”
	public static final int FEE_STATUS_RENT_TODO = 2;

	//支付模式:微信
	public static final Integer FEE_PAYMODEL_WECHAT = 0;
	
	//支付模式:现金
	public static final Integer FEE_PAYMODEL_CASH = 1;
	
	//支付模式:银行转账
	public static final Integer FEE_PAYMODEL_BANK = 2;
	
	//支付模式:支付宝
	public static final Integer FEE_PAYMODEL_ALIPAY = 3;
	
	private Integer id;
	
	private Room room;
	
	private TenantUser tenantUser;
	
	private LandlordOwnerUser landlordUser;
	
	//所属合约
	private Agreement agreement;
	
	// 时间段的应收费用, 总额
	private BigDecimal amountRecv;
	
	// 时间段的实收费用
	private BigDecimal amountActual;
	
	// 时间段开始
	private String dateBeginRecv;
	
	// 时间段结束
	private String dateEndRecv;
	
	// 缴款日期
	private String dateActual;
	
	// 余额， 为正表示有存， 负表示还有欠缴
	private BigDecimal balance;
	
	//上次余额
	private BigDecimal prevBalance;
	
	// 仅房租
	private BigDecimal rental;
	
	//房租应收
	private BigDecimal rentalCalc;
	//押金实收
	private BigDecimal depositActual;
	
	// 费用类型: 0  待确认 book; 1  已确认 confirm; 2 已收租  默认为1
	private Integer type;
	
	//经办人
	private LandlordUser agent;
	
	//备注
	private String remark;
	
	// 附加费
	private List<FeeAdditionRecord> feeAdditionRecords;
	
	// 缴费方式(微信：0；现金：1；银行：2；支付宝：3)
	private Integer payMode;
	
	private Integer version;
	
	// 0 - 删除， 1 - 正常(已收租)， 2 - 待确认（未收租）
	private Integer status;
	
	//@Transient 固定费用总额
	private BigDecimal fixedFeeTotalAmount; 
	
	// 仪表附加费
	private List<FeeAdditionRecord> meterFeeAdditionRecords;
	
	//@Transient 冗余
	private Integer rentalOrderId;
	
	private Date createDate;
	
	@Id
	@GeneratedValue
	@Column(name = "feeid")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "roomid")
	@Index(name="idx_ra_fee_roomid")
	public Room getRoom() {
		return room;
	}

	public void setRoom(Room room) {
		this.room = room;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "userid")
	public TenantUser getTenantUser() {
		return tenantUser;
	}

	public void setTenantUser(TenantUser tenantUser) {
		this.tenantUser = tenantUser;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "createuserid")
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "agreement_id")
	@Index(name="idx_ra_fee_agreement_id")
	@NotFound(action = NotFoundAction.IGNORE)
	public Agreement getAgreement() {
		return agreement;
	}

	public void setAgreement(Agreement agreement) {
		this.agreement = agreement;
	}

	@Column(name = "amount_recv")
	public BigDecimal getAmountRecv() {
		return amountRecv;
	}

	public void setAmountRecv(BigDecimal amountRecv) {
		this.amountRecv = amountRecv;
	}

	@Column(name = "amount_actual")
	public BigDecimal getAmountActual() {
		return amountActual;
	}

	public void setAmountActual(BigDecimal amountActual) {
		this.amountActual = amountActual;
	}

	@Column(name = "date_begin_recv")
	public String getDateBeginRecv() {
		return dateBeginRecv;
	}

	public void setDateBeginRecv(String dateBeginRecv) {
		this.dateBeginRecv = dateBeginRecv;
	}

	@Column(name = "date_end_recv")
	public String getDateEndRecv() {
		return dateEndRecv;
	}

	public void setDateEndRecv(String dateEndRecv) {
		this.dateEndRecv = dateEndRecv;
	}

	@Column(name = "date_actual")
	public String getDateActual() {
		return dateActual;
	}

	public void setDateActual(String dateActual) {
		this.dateActual = dateActual;
	}

	@Column(name = "balance")
	public BigDecimal getBalance() {
		return balance;
	}

	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}

	@Column(name = "rental")
	public BigDecimal getRental() {
		return rental;
	}

	public void setRental(BigDecimal rental) {
		this.rental = rental;
	}

	@Column(name = "fee_type")
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@Column(name = "version_id")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Column(name = "data_status")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@OneToMany(targetEntity = FeeAdditionRecord.class, mappedBy = "feeRecord", cascade=CascadeType.ALL, orphanRemoval=true)
	public List<FeeAdditionRecord> getFeeAdditionRecords() {
		return feeAdditionRecords;
	}

	public void setFeeAdditionRecords(List<FeeAdditionRecord> feeAdditionRecords) {
		this.feeAdditionRecords = feeAdditionRecords;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "adminid")
	public LandlordUser getAgent() {
		return agent;
	}

	public void setAgent(LandlordUser agent) {
		this.agent = agent;
	}
	
	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public Integer getPayMode() {
		return payMode;
	}

	public void setPayMode(Integer payMode) {
		this.payMode = payMode;
	}
		@Transient
	public BigDecimal getFixedFeeTotalAmount() {
		return fixedFeeTotalAmount;
	}

	public void setFixedFeeTotalAmount(BigDecimal fixedFeeTotalAmount) {
		this.fixedFeeTotalAmount = fixedFeeTotalAmount;
	}
	
	@Transient
	public List<FeeAdditionRecord> getMeterFeeAdditionRecords() {
		return meterFeeAdditionRecords;
	}

	public void setMeterFeeAdditionRecords(
			List<FeeAdditionRecord> meterFeeAdditionRecords) {
		this.meterFeeAdditionRecords = meterFeeAdditionRecords;
	}
	
	@Transient
	public Integer getRentalOrderId() {
		return rentalOrderId;
	}

	public void setRentalOrderId(Integer rentalOrderId) {
		this.rentalOrderId = rentalOrderId;
	}

	public Date getCreateDate() {
		return createDate;
	}

	@Column(columnDefinition = "datetime default now()")
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public BigDecimal getRentalCalc() {
		return rentalCalc;
	}

	public void setRentalCalc(BigDecimal rentalCalc) {
		this.rentalCalc = rentalCalc;
	}
	
	public BigDecimal getDepositActual() {
		return depositActual;
	}

	public void setDepositActual(BigDecimal depositActual) {
		this.depositActual = depositActual;
	}

	public BigDecimal getPrevBalance() {
		return prevBalance;
	}

	public void setPrevBalance(BigDecimal prevBalance) {
		this.prevBalance = prevBalance;
	}
	
}
